import { ACCESS_ENUM } from '@/access/accessEnum'
import { devRoutes } from './devroutes'
import type { RouteRecordRaw } from 'vue-router'
import { apps } from '@/microApps'
import { toolboxRoutes } from '@/views/toolbox/routes'
import { routes as userRoutes } from '@/views/user/components/routes'
export const MenuRoutes = [
    {
        path: '/',
        name: 'index',
        meta: {
            title: '首页'
        },
        component: () => import('@/views/index.vue')
    },
    {
        path: '/problem',
        name: 'problem-list',
        meta: {
            title: '题目'
        },
        // @ts-ignore
        component: () => import('@/views/Problem/ProblemList.vue')
    },
    {
        path: '/training',
        name: 'training-list',
        meta: {
            title: '题单'
        },
        // @ts-ignore
        component: () => import('@/views/Training/TrainingList.vue')
    },
    {
        path: '/contest',
        name: 'contest-list',
        meta: {
            title: '比赛'
        },
        // @ts-ignore
        component: () => import('@/views/Contest/ContestList.vue')
    },
    {
        path: '/record',
        name: 'record-list',
        meta: {
            title: '记录'
        },
        // @ts-ignore
        component: () => import('@/views/Record/RecordList.vue')
    },
    {
        path: '/blog',
        name: 'blog-list',
        meta: {
            title: '博客'
        },
        // @ts-ignore
        component: () => import('@/views/blog/BlogList.vue')
    },
    ...toolboxRoutes,
    {
        path: '/chat',
        name: 'chat',
        meta: {
            title: '聊天',
            access: ACCESS_ENUM.USER
        },
        // @ts-ignore
        component: () => import('@/views/Chat/ChatView.vue')
    },
    {
        path: '/file',
        name: 'file-list',
        meta: {
            title: '文件'
        },
        // @ts-ignore
        component: () => import('@/views/file/FileTransfer.vue')
    }
]
const BasicLayoutRoutes = [
    ...MenuRoutes,
    {
        path: '/ide',
        name: 'ide',
        meta: {
            title: '在线IDE'
        },
        component: () => import('@/views/editor/EditorView.vue')
    },

    {
        path: '/noauth',
        name: '401',
        // @ts-ignore
        component: () => import('@/views/NoAuth.vue'),
        meta: {
            // access: ACCESS_ENUM.NOT_LOGIN,
        }
    },
    {
        path: '/profile',
        name: 'profile',
        meta : {
            title: '个人资料'
        },
        component: () => import('@/views/user/UserProfile.vue'),
    },
    {
        path: '/file-box',
        name: 'file-box',
        component: () => import('@/views/file/FileCarrier.vue'),
        meta: {
            title: '文件盒子'
        }
    },
    {
        path: '/notfound',
        name: '404',
        component: () => import('@/views/NotFound.vue'),
        meta: {}
    },
    {
        path: '/:pathMatch(.*)*',
        name: '404',
        component: () => import('@/views/NotFound.vue'),
        meta: {}
    },
    {
        path: '/training/:id([\\d]+)',
        name: 'trainging',
        component: () => import('@/views/training/TrainingView.vue'),
        meta: {}
    },
    {
        path: '/problem/:id([\\d-\\w]+)',
        name: 'problem',
        component: () => import('@/views/user/UserRegister.vue'),
        meta: {
            access: ACCESS_ENUM.NOT_LOGIN
        }
    },
    {
        path: '/problem/:id([\\d-\\w]+)',
        name: 'problem',
        component: () => import('@/views/problem/ProblemView.vue'),
        meta: {
            access: ACCESS_ENUM.USER
        }
    },
    {
        path: '/record/:id([\\d-\\w]+)',
        name: 'record',
        component: () => import('@/views/record/RecordView.vue'),
        meta: {
            access: ACCESS_ENUM.USER
        }
    },
    {
        path: '/blog/create',
        name: 'blog-create',
        meta: {},
        component: () => import('@/views/blog/BlogCreate.vue')
    },
    {
        path: '/blog/edit/:id([\\d-\\w]+)',
        name: 'blog-edit',
        meta: {},
        component: () => import('@/views/blog/BlogEdit.vue')
    },
    {
        path: '/blog/:id([\\d-\\w]+)',
        name: 'blog',
        // @ts-ignore
        component: () => import('@/views/blog/BlogView.vue'),
        meta: {}
    },
    ...devRoutes,
    ...apps.map((app) => {
        return {
            path: app.activeRule,
            name: '骨架屏',
            meta: {},
            children: [
                {
                    path: ':pathMatch(.*)*',
                    name: `${app.name}-child`,
                    redirect: '/notfound'
                }
            ]
        } as RouteRecordRaw
    })
] as RouteRecordRaw[]

const EmptyLayoutRoutes = [
    ...userRoutes,
    {
        path: '',
        component: () => import('@/views/user/components/PersonalCenter.vue')
    }
]

export const routes = [
    {
        path: '/',
        name: 'BasicLayout',
        component: () => import('@/layouts/BasicLayout.vue'),
        children: BasicLayoutRoutes
    },
    {
        path: '/user/login',
        name: 'login',
        component: () => import('@/views/user/UserLogin.vue'),
        meta: {
            access: ACCESS_ENUM.NOT_LOGIN
        }
    },
    {
        path: '/user/register',
        name: 'register',
        component: () => import('@/views/user/UserRegister.vue'),
        meta: {
            access: ACCESS_ENUM.NOT_LOGIN
        }
    },
    {
        path: '/user',
        name: 'UserLayout',
        component: () => import('@/layouts/UserLayout.vue'),
        children: EmptyLayoutRoutes
    }
]
